package com.service;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.dao.IBisMdlDefDao;
import com.icim.service.ICIMBaseService;
import com.model.Bis_mdl_def;
import com.tx.Xplstmdl.XplstmdlI;
import com.tx.Xplstmdl.XplstmdlO;
import com.tx.Xplstmdl.XplstmdlOA;
import com.util.MqOpe;

@Scope("prototype")
@Service("XplstmdlService")
public class XplstmdlService extends ICIMBaseService{
	private Logger logger = Logger.getLogger(XplstmdlService.class);
	@Autowired
	private XplstmdlI xplstmdlI;
	
	@Autowired
	private XplstmdlO xplstmdlO; 
	
	
	@Autowired
	private IBisMdlDefDao bisMdlDefDao;
	
	@Autowired
	private MqOpe mqOpe;
	
	public String subMainProc(String strInMsg){
		List<Bis_mdl_def> bisMdlDefList = new ArrayList<Bis_mdl_def>();
		xplstmdlI = (XplstmdlI) mqOpe.inStr2Obj(strInMsg,xplstmdlI);
		logger.info("InTrx is "+ strInMsg );
		bisMdlDefList = this.findAllMdlDef();
		xplstmdlO = this.setOutTrx( bisMdlDefList );
		logger.info(mqOpe.obj2Str(xplstmdlO));
		return mqOpe.obj2Str(xplstmdlO);
	}
	
	public List<Bis_mdl_def> findAllMdlDef(){
//		List<Ret_wo> retWoList = new ArrayList<Ret_wo>();
		String querySql=" from Ret_wo ";
		List<Bis_mdl_def> retWoList = bisMdlDefDao.find( querySql );
		return retWoList ;
	}
	
	public XplstmdlO setOutTrx( List<Bis_mdl_def> bisMdlDefList ){
		XplstmdlO xplstmdlO = new XplstmdlO();
		xplstmdlO.setTrx_id("XPLSTPRD");
		xplstmdlO.setType_id("O");
		xplstmdlO.setRtn_code("0000000");
		xplstmdlO.setRtn_mesg("success");
		
		List<XplstmdlOA> oaryList = new ArrayList<XplstmdlOA>();
		for(Bis_mdl_def bis_mdl_def: bisMdlDefList){
			XplstmdlOA xplstworOA = new XplstmdlOA();
			xplstworOA.setMdl_id(bis_mdl_def.getMdl_id());
			xplstworOA.setMdl_cate(bis_mdl_def.getMdl_cate());
			xplstworOA.setMdl_typ(bis_mdl_def.getMdl_typ());
			xplstworOA.setMdl_code(bis_mdl_def.getMdl_code());
			xplstworOA.setMdl_size(bis_mdl_def.getMdl_size());
			xplstworOA.setMdl_ec_code(bis_mdl_def.getMdl_ec_code());
			xplstworOA.setMdl_param(bis_mdl_def.getMdl_param());
			xplstworOA.setMdl_dsc(bis_mdl_def.getMdl_dsc());
			oaryList.add(xplstworOA);
		}
		xplstmdlO.setOary(oaryList);
		xplstmdlO.setTbl_cnt(String.valueOf( oaryList.size()));
		return xplstmdlO;
	}
	
}
